Generic Variance
Variance describes how a generic type's compatibility changes when its type parameter has an inheritance relationship. Covariance allows a generic producer of a more derived type to be used where a producer of a base type is expected. Contravariance reverses the direction and is useful for consumers: a consumer capable of accepting a base type can generally be used where a consumer of a derived type is expected. In C#, interfaces and delegates can explicitly declare variance using out and in.
Covariance is commonly associated with producers and uses an out-style relationship.
Contravariance is commonly associated with consumers and uses an in-style relationship.
C# explicitly supports variance annotations on certain generic interfaces and delegates.
Java uses use-site wildcards such as ? extends T and ? super T to express variance.
Mutable collections are generally invariant because allowing both reads and writes can violate type safety.